package com.gobang.service;

import com.gobang.domain.vo.MatchResponseVO;
import com.gobang.service.impl.MatchServiceImpl;

import java.time.LocalDateTime;

/**
 * 匹配系统服务接口
 * 供实时通信模块调用的匹配逻辑服务
 * 
 * @author System
 * @since 1.0.0
 */
public interface MatchService {

    /**
     * 加入匹配队列
     *
     * @param userId
     * @return
     */
    MatchResponseVO joinMatchQueue(Long userId);

    /**
     * 取消匹配
     *
     * @param userId
     * @return
     */
    boolean cancelMatch(Long userId);

    /**
     * 获取匹配系统状态
     *
     * @return
     */
    MatchSystemStatus getMatchSystemStatus();

    /**
     * 手动触发匹配
     */
    void triggerMatch();

    /**
     * 匹配系统状态
     */
    public static class MatchSystemStatus {
        private final boolean running;
        private final int queueSize;
        private final long avgWaitTime;
        private final double avgScore;
        private final LocalDateTime timestamp;

        public MatchSystemStatus(boolean running, int queueSize, long avgWaitTime, double avgScore, LocalDateTime timestamp) {
            this.running = running;
            this.queueSize = queueSize;
            this.avgWaitTime = avgWaitTime;
            this.avgScore = avgScore;
            this.timestamp = timestamp;
        }

        public boolean isRunning() { return running; }
        public int getQueueSize() { return queueSize; }
        public long getAvgWaitTime() { return avgWaitTime; }
        public double getAvgScore() { return avgScore; }
        public LocalDateTime getTimestamp() { return timestamp; }

        @Override
        public String toString() {
            return String.format("MatchSystemStatus{running=%s, queue=%d, avgWait=%ds, avgScore=%.1f, time=%s}",
                    running, queueSize, avgWaitTime, avgScore, timestamp);
        }
    }

    /**
     * 匹配对手信息
     */
    public static class MatchOpponentInfo {
        private Long id;
        private String username;
        private Integer currentScore;

        public MatchOpponentInfo() {}

        public MatchOpponentInfo(Long id, String username, Integer currentScore) {
            this.id = id;
            this.username = username;
            this.currentScore = currentScore;
        }

        // Getters and Setters
        public Long getId() { return id; }
        public void setId(Long id) { this.id = id; }

        public String getUsername() { return username; }
        public void setUsername(String username) { this.username = username; }

        public Integer getCurrentScore() { return currentScore; }
        public void setCurrentScore(Integer currentScore) { this.currentScore = currentScore; }
    }
    
//    /**
//     * 处理匹配请求
//     *
//     * @param userId 用户ID
//     * @return 匹配处理结果
//     */
//    MatchResult processMatchRequest(Long userId);
//
//    /**
//     * 处理取消匹配请求
//     *
//     * @param userId 用户ID
//     * @return 取消匹配处理结果
//     */
//    CancelMatchResult processCancelMatchRequest(Long userId);
//
//    /**
//     * 匹配处理结果
//     */
//    public static class MatchResult {
//        private boolean success;
//        private String status; // MATCHING, MATCH_SUCCESS
//        private Integer waitTime;
//        private Integer queuePosition;
//        private String roomId; // 匹配成功时的房间ID
//        private MatchOpponentInfo opponent; // 匹配成功时的对手信息
//        private String playerColor; // 匹配成功时的玩家颜色
//        private String startTime; // 匹配成功时的开始时间
//        private String errorCode;
//        private String errorMessage;
//
//        public MatchResult() {}
//
//        public static MatchResult matching(Integer waitTime, Integer queuePosition) {
//            MatchResult result = new MatchResult();
//            result.setSuccess(true);
//            result.setStatus("MATCHING");
//            result.setWaitTime(waitTime);
//            result.setQueuePosition(queuePosition);
//            return result;
//        }
//
//        public static MatchResult matchSuccess(String roomId, MatchOpponentInfo opponent,
//                                             String playerColor, String startTime) {
//            MatchResult result = new MatchResult();
//            result.setSuccess(true);
//            result.setStatus("MATCH_SUCCESS");
//            result.setRoomId(roomId);
//            result.setOpponent(opponent);
//            result.setPlayerColor(playerColor);
//            result.setStartTime(startTime);
//            return result;
//        }
//
//        public static MatchResult failure(String errorCode, String errorMessage) {
//            MatchResult result = new MatchResult();
//            result.setSuccess(false);
//            result.setErrorCode(errorCode);
//            result.setErrorMessage(errorMessage);
//            return result;
//        }
//
//        // Getters and Setters
//        public boolean isSuccess() { return success; }
//        public void setSuccess(boolean success) { this.success = success; }
//
//        public String getStatus() { return status; }
//        public void setStatus(String status) { this.status = status; }
//
//        public Integer getWaitTime() { return waitTime; }
//        public void setWaitTime(Integer waitTime) { this.waitTime = waitTime; }
//
//        public Integer getQueuePosition() { return queuePosition; }
//        public void setQueuePosition(Integer queuePosition) { this.queuePosition = queuePosition; }
//
//        public String getRoomId() { return roomId; }
//        public void setRoomId(String roomId) { this.roomId = roomId; }
//
//        public MatchOpponentInfo getOpponent() { return opponent; }
//        public void setOpponent(MatchOpponentInfo opponent) { this.opponent = opponent; }
//
//        public String getPlayerColor() { return playerColor; }
//        public void setPlayerColor(String playerColor) { this.playerColor = playerColor; }
//
//        public String getStartTime() { return startTime; }
//        public void setStartTime(String startTime) { this.startTime = startTime; }
//
//        public String getErrorCode() { return errorCode; }
//        public void setErrorCode(String errorCode) { this.errorCode = errorCode; }
//
//        public String getErrorMessage() { return errorMessage; }
//        public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
//    }
//
//    /**
//     * 取消匹配处理结果
//     */
//    public static class CancelMatchResult {
//        private boolean success;
//        private String errorCode;
//        private String errorMessage;
//
//        public CancelMatchResult() {}
//
//        public static CancelMatchResult success() {
//            CancelMatchResult result = new CancelMatchResult();
//            result.setSuccess(true);
//            return result;
//        }
//
//        public static CancelMatchResult failure(String errorCode, String errorMessage) {
//            CancelMatchResult result = new CancelMatchResult();
//            result.setSuccess(false);
//            result.setErrorCode(errorCode);
//            result.setErrorMessage(errorMessage);
//            return result;
//        }
//
//        // Getters and Setters
//        public boolean isSuccess() { return success; }
//        public void setSuccess(boolean success) { this.success = success; }
//
//        public String getErrorCode() { return errorCode; }
//        public void setErrorCode(String errorCode) { this.errorCode = errorCode; }
//
//        public String getErrorMessage() { return errorMessage; }
//        public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
//    }
//

} 